<?php
class Category_tree_create extends CI_MODEL
	{
		public function __construct()
			{
				parent::__construct();
				$this->load->database();
			}

		function module_type_details()
			{
				$menu_tree_string = "";
				$this->db->select('id,module_type_name,module_type_class');
				$query = $this->db->from('proposal_module_type');
				$module_type_details = $this->db->get()->result_array();
				
				/*
				echo("<pre>");
				print_r($module_type_details);
				$sql = $this->db->last_query();
				//echo($sql."<br/>");
				//exit;
				*/
				
				
				foreach($module_type_details as $module_type_details_array)
					{
						$menu_tree_string = $menu_tree_string  . "<h2><span id=\"\">"  . $module_type_details_array['module_type_name'] . "</span></h2><ul>";
						$this->db->select('proposal_category_tree.id,proposal_category_name.category_name,proposal_category_tree.parent_id');								
						$this->db->from('proposal_category_name');
						$this->db->where('category_type',$module_type_details_array['module_type_class']);
						$this->db->join('proposal_category_tree', 'proposal_category_tree.parent_id = proposal_category_name.id');
						$this->db->group_by('parent_id');
						$query = $this->db->get();
						$category_details = $query->result_array();	
						
						/*
						echo("<pre>");
						//echo("Category_up_array");		
						print_r($category_details);
						$sql = $this->db->last_query();
						//echo($sql."<br/>");
						//exit;
						*/		
						
						
						foreach($category_details as $category_details_array)
							{
								$menu_tree_string = $menu_tree_string  . "<li id=\""  . $category_details_array['parent_id'] . "\">" . $category_details_array['category_name'] . "</li>";
								$this->db->select('proposal_category_tree.id,proposal_category_tree.parent_id,proposal_category_name.category_name');								
								$this->db->from('proposal_category_tree');
								$this->db->where('parent_id',$category_details_array['parent_id']);
								$this->db->join('proposal_category_name', 'proposal_category_name.id = proposal_category_tree.id');
								$query = $this->db->get();
								$category_details_sub_details = $query->result_array();
								
								/*
								echo("<pre>");
								//echo("Category_details_sub_details");		
								print_r($category_details_sub_details);
								$sql = $this->db->last_query();
								//echo($sql."<br/>");
								//exit;
								*/
								
								foreach($category_details_sub_details as $category_details_sub_details_array)
									{
										$menu_tree_string = $menu_tree_string  . "<ul><li id=\"" . $category_details_sub_details_array['id'] . "\">" .$category_details_sub_details_array['category_name'] . "</li>";
									}
									
									$menu_tree_string = $menu_tree_string  . "</ul>";
							}		
							
						$menu_tree_string = $menu_tree_string  . "</ul>";	
						
					}
				//echo($menu_tree_string);
				return $menu_tree_string;
				
			}	
	}
?>			